Counting points on curves over families in polynomial time