I believe it performs the same function as the mucus lining the nasal passages, and for the same reason. Both sets of orifices connect extremely delicate and easily damaged tissues with outside air, which is full of potentially damaging foreign bodies - dust, pollen, insects etc. The mucus and wax act as traps for any such invading organism which may, if unchecked, cause damage to the hearing or scent organs. The wax and mucus are periodically discharged naturally, taking the unwelcome visitors outside the body with them.