function [ext_dist] = calc_pairwise_dist_front(A1, A2, lowdim); 

len = round(size(A1,2)/lowdim);
dist = (1:len)*0.0;
for i=1:len,
  dist1 = 0.0;
%  for j=0:(len-1),
%    k = mod(i + j, len)+1;
  k = i;
  B = A1(:,((i-1)*lowdim+1):(i*lowdim))'*A2(:,((k-1)*lowdim+1):(k*lowdim));
  S = svd(B);
  S_flag = (S < 1.0);
  dist1 = dist1 + sum(sum((acos(S).*S_flag).^(2)));
  %end
  dist1= sqrt(dist1/len);
  dist(i) = dist1;
end
ext_dist = min(min(dist));
return;
% keyboard;
    






