Stable shape comparison by persistent homology