A model for the origin of heterospory