code: function flatten(array, accu) {
    if(!accu){
      accu = [];
    }
    array.forEach(function(a){
      if(Array.isArray(a)) {
        flatten(a, accu)
      } else {
        accu.push(a)
      }
    });
    return accu
  }
docs: Example of use of EMD distance using histograms 1. Build 2 histograms from images using calcHist 2. Transform each histogram to a 64 x 4 (hist, b, g, r) x 1 normalized signatures in BGR space 3. Compute the cost matrix (64 x 64 x 1), calculating the cost in LUV space 4. Run EMD algorithm  / Useful flatten function for step 2