Implement kernel median filter