Statistical method for determining ages of globular clusters by fitting isochrones