What are the functions of ovaries and testes in animals?