Ecological and Evolutionary Processes Drive the Origin and Maintenance of Imperfect Mimicry