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.
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.