Learning Topology of Curves with Application to Clustering