Learning a Similarity Metric Discriminatively with Application to Ancient Character Recognition