There are a number of reasons why an engine might misfire while it is idling. Usually misfires occur when there is no spark, the air/fuel mixture is out of balance or the engine is losing compression.
Bad or damaged spark plugs can prevent sparks from occurring. Worn or damaged fuel-injector filters can cause what is known as lean misfire, when there is too little gas in the air/fuel mixture. Loss of compression means a cylinder isn't getting the right amount of air/fuel mixture before it can be ignited. This could be caused by a leaky exhaust valve or blown head gasket.