Dark energy and dark matter as curvature effects