Mining the epistatic gene loci for complex diseases is an important research topic in recent years. The existing epistasis detection methods have the shortcomings of high complexity, low efficiency, high false positive rate, inability to deal with large-scale genome-wide data, etc. In this work, we propose a epistasis mining method which using k-tree optimizing Bayesian network (BN) (KtreeBnIp). Firstly, it constructs the k-tree including large-scale of SNP loci and phenotype by sampling the Dandelion code uniformly. Then it decomposes k-tree into different k-cliques by using the graph decomposition algorithm based on neighbor nodes. For the nodes in each k-clique, the integer linear programming optimizing Bayesian network (ILPBN) is used to obtain the sub-network quickly and accurately. Finally, it merges all the sub-networks to obtain the whole network. It repeats the above operations (k-tree generation, k-tree decomposition, network generation) several times and gets the final network according to the frequency of edges, and thus to obtain the epistatic loci affecting phenotype. We compare KtreeBnIp with the current popular epistasis mining algorithms using both simulated and real age-related macular degeneration(AMD) datasets. Experiment results show that KtreeBnIp has better epistasis detection accuracy, higher F1-score, and lower false positive rate. Most importantly, it can be used in large-scale of SNPs for epistasis detection.