template for findtopkmatchingfromarrays