The heater in a car blows cold air while idling because the engine is not producing enough heat to warm the coolant that flows through the heater core. The coolant is heated by the engine as it flows through the engine's cylinder head and water pump. When the engine is idling, the coolant does not flow through the engine quickly enough to absorb enough heat, so the coolant that flows through the heater core is not hot enough to warm the air that blows through the vents.
As the engine speed increases, the coolant flows through the engine more quickly and absorbs more heat. This hotter coolant then flows through the heater core and warms the air that blows through the vents. Therefore, the heater blows hot air when the car is driving.