I think I found an answer.
It seems like the right way to do it is to use unfold and fold functions.
With the unfold function one can create the same sliding window slices that a convolution operation slides over.
But, one thing that remains unclear is how I can apply my own function (e.g. euclidean distance) efficiently (e.g. without a python for-loop) over those slices.