When and why did masturbation evolve in primates? A new study provides clues