Update functions.R

add a threshold for covariance matrix