function [trainClasses,trainData]=balanceClasses(trainClasses,trainData,noClasses,eps)
    while sum(abs(diff(histcounts(trainClasses,noClasses))))> 0+eps
        mostFrequent=find(trainClasses==mode(trainClasses));
        
        r=floor(size(mostFrequent,2)*rand(1)+1);
        delIndex=mostFrequent(r);
        trainClasses=trainClasses([1:delIndex-1,delIndex+1:end]);
        trainData=trainData([1:delIndex-1,delIndex+1:end],:);
    end
    assert(size(trainClasses,2)>0)
end