They could be insect larvae or any kind of land or aquatic worm. Some fall into the water and breed, some are dropped by birds, some are laid there by insects. They gather in the filter because it is a nice safe spot away from predators and filled with oxygenated water.
Sometimes these 'worms' are insect larvae, but the worms and non-worms get there by birds, laid there by insects, or they simply fall into the water and start to breed.
Worms reproduce naturally, and thus if any of them find their way into your pond, they may start breeding. Short of calling an exterminator or some sort of aquatic-industrial business, there's not much to do about them.