Speed up CreateIndex by using matrices instead of a dataframe