Fixes memory leak when running knnSearch

Matrix static_casts the pointer to a char*, trying to delete that creates a memory leak.