Create geometry from "unordered" vertices

I want to combine the coordinates of multiple vertices to obtain a new set of vertices I’ll use to create a new geometry. I did it but the triangles are all messy and connect random parts of the model because the indexes have no connection to the position of those vertices in the space. I could use morph targets but they’re limited to 8 models, so I opted for a more flexible approach but there’s this problem

Is there a way to obtain the right order for the indexes? Even increasing the max limit of morph targets could be a solution but I need at least 20, and I may need even more in the future, so the solution has to be scalable