function dist = feature_distance(feature_A, feature_B)
	% dist = feature_distance(feature_A, feature_B)
	%	evaluate the distance between feature A and a set of features B
	%
	%	Input:
	%		feature_A	3 x n_neighbours_A 
	%		feature_B	3 x n_neighbours_B x n_B
	%	
	%	feature_A and feature _B are sets of features generated by build_feature
	%	features can be of different size, but it is required that
	%		n_neighbours_B <= n_neighbours_A
	%
	%	Output:
	%		dist		1 x n_B
	%	a generalised distance between features
	%	
	
	%% sanity check
	assert(size(feature_A, 1) == 3);
	assert(size(feature_B, 1) == 3);
	assert(ismatrix(feature_A));
	%assert(ndims(feature_B) == 3);
	n_neighbours_A = size(feature_A, 2);
	n_neighbours_B = size(feature_B, 2);
	n_B		= size(feature_B, 3);
	assert(n_neighbours_B <= n_neighbours_A, 'feature size of B must be <= feature size of A');
	
	%% measure distance between features
	% ordering of neighbours in feature B does not matter
	A_to_B	= reshape(feature_B, [3 1 n_neighbours_B n_B]) - feature_A;
	rrAB	= reshape(sum(A_to_B.^2,1), [n_neighbours_A n_neighbours_B n_B]);
	% evaluate minimal distance with best ordering 
	rrmin	= sort(min(rrAB, [], 2), 1, 'ascend');
	% only measure distance to n_neighbours_B candidates
	dist	= sum(rrmin(1:n_neighbours_B,:), 1);
	dist	= dist(:);
	
	% naive implementation: ordering matters
	%A_to_B	= feature_B - feature_A;
	%dist	= sum(sum(A_to_B.^2, 1), 2);
	%dist	= dist(:);
end